<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!--   引入 echarts.js -->
    <script src="/page/echarts.js"></script>
    <!-- 引入 jQuery.js -->
    <script src="/page/jquery-3.7.0.min.js"></script>
</head>
<body>
<!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
<div id="main" style="width: 1000px;height:550px;"></div>
<script type="text/javascript">
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option;

    $.get('http://localhost:8080/NovelTypeNum', function (data){
        var novelTypes = data.map(function(item) {
            return item.novelType;
        });
        var typeNums = data.map(function(item) {
            return item.typeNum;
        });
        var avgClicks = data.map(function(item) {
            return item.avgClick;
        }).slice(0, 10);

        // 配置图表选项
        // 配置图表选项
        var option = {
            title: {
                text: '前十类小说类型数量',
                left: 'center'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            xAxis: {
                type: 'category',
                data: novelTypes
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                name: '数量',
                type: 'bar',
                data: typeNums,
                itemStyle: {
                    normal: {
                        color: '#FF0000' // 设置颜色
                    }
                }
            }]
        };

        if (option && typeof option === 'object') {
            myChart.setOption(option);
        }
    });
</script>
</body>
</html>
